package com.xyz.study.design_mode.d_factory_method.mode;

import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 具体的对象B的具体的工厂
 * @author XYZ
 * @version 1.0.0
 * @since 2021/1/18
 */
public class FactoryConcreteB extends Factory{
    private Map<String, ProductConcreteB> store = new HashMap<>();
    @Override
    protected Product generate() {
        return new ProductConcreteB();
    }

    @Override
    protected Product register(String name, Product product) {
        if (StringUtils.isEmpty(name) || null == product){
            throw new RuntimeException("注册参数 name，product 不能为空");
        }
        if (product instanceof ProductConcreteB){
            store.put(name, (ProductConcreteB) product);
        }
        return store.get(name);
    }
}
